package stu.day33_day38.day33;

import java.util.Scanner;

public class hw3 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int n = sc.nextInt();

        int[][] arr1 = new int[x][y];
        int[][] arr2 = new int[x][y];

        for(int i =0;i<x;i++){
            for(int j=0;j<y;j++){
                arr1[i][j]=0;
                arr2[i][j]=0;
            }

        }
        System.out.println();


        for(int p=0;p<n;p++){
            int i = sc.nextInt();
            int j = sc.nextInt();
            arr1[i][j]=1;
            arr2[i][j]=1;
        }

        for(int i =0;i<x;i++){
            for(int j=0;j<y;j++){
                System.out.print(arr1[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println();



        int num1 = 0;
        dfs1(0,0,x,y,arr1);
        for(int i =0;i<x;i++){
            for(int j=0;j<y;j++){
                System.out.print(arr1[i][j]+" ");
               if(arr1[i][j]==0){
                   num1+=1;
               }
            }
            System.out.println();
        }
        System.out.println();
        int num2 = 0;
        dfs2(0,0,x,y,arr2);
        for(int i =0;i<x;i++){
            for(int j=0;j<y;j++){
                System.out.print(arr2[i][j]+" ");
                if(arr2[i][j]==0){
                    num2+=1;
                }
            }
            System.out.println();
        }

        int num = num1-num2;

        System.out.println(num1+" "+num2);


    }



    public static boolean dfs1(int i,int j,int n,int m,int[][] arr){
        if(i==n-1&&j==m-1){
            arr[i][j]=9;
            return true;
        }
        if(i>=0&&i<n&&j>=0&&j<m){
            if(arr[i][j]==0){
                boolean flag1 = dfs1(i,j+1,n,m,arr);
                boolean flag2 = dfs1(i+1,j,n,m,arr);
                if(flag1||flag2){
                    arr[i][j]=9;
                }
                return flag1||flag2;
            }
            if(arr[i][j]==9){
                return true;
            }
        }
        return false;
    }

    public static void dfs2(int i,int j,int n,int m,int[][] arr) {
        if (i >= 0 && i < n && j >= 0 && j < m) {
            if (arr[i][j] == 0) {
                arr[i][j] = 9;
                dfs2(i + 1, j, n, m, arr);
                dfs2(i, j + 1, n, m, arr);
            }
        }
    }





}
